package priv.yiyuan.example.design.chain.command01;

/**
 * 上下文 被所有命令操作的对象
 *
 * @author YiYuan
 * @data 2025/10/9
 * @apoNote
 */
public class Account {

    private Double balance;

    public Account(Double balance) {
        this.balance = balance;
    }

    public void deposit(Double amount) {
        balance += amount;
        System.out.println("存款: " + amount + ", 新余额: " + balance);
    }

    public void withdraw(Double amount) {
        if (balance >= amount) {
            balance -= amount;
            System.out.println("取款: " + amount + ", 新余额: " + balance);
        }
        else {
            System.out.println("余额不足, 取款失败！");
        }
    }

    public Double getBalance() {
        return balance;
    }

}
